package com.memory.demo.Controller;

import com.memory.demo.service.AcceptimageService;
import com.memory.demo.service.MadeService;
import com.memory.demo.service.PaintService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

@RestController
public class AccpetPaingtContorller {

    @Resource
    private  AcceptimageService acceptimageService;
    @Resource
    private MadeService madeService;
    @Resource
    private PaintService paintService;
    @Value("target/classes/static/1234.jpg")
    private  String baseImagePath;
    @Value("${path.saveFilePath}")
    private  String saveFilePath;


    @PutMapping("/acceptimage")
    @CrossOrigin
    public String acceptimage(String title,  MultipartFile image,int xmove,int ymove,String text) throws IOException {

        String OverrideImage= acceptimageService.singleFileUpload(image); // 存储小图
        String OverrideImagePath = OverrideImage.split("&")[0];  //得到小图路径
         saveFilePath = saveFilePath+OverrideImage.split("&")[1]+".jpg";//得到小图文件名
        BufferedImage buffImg = MadeService.watermark(new File(baseImagePath), new File(OverrideImagePath), xmove, ymove, 1.0f); //大图与小图按偏移量合成
        String savepath =madeService.generateWaterFile(buffImg, saveFilePath); //将合成后的图片保存在下面那个地址  这里savepath=saveFilePath


        String path= paintService.tuxiangjiawenzi(title,text,savepath,OverrideImage.split("&")[1]); //合成地址

        return  path.replaceAll("/www/wwwroot/","http://");
    }
}
